package com.zhengtoon.mctoon.conv.utils;

import com.bjtoon.framework.sdk.toon.tooncode.ToonCodeInfo;
import com.zhengtoon.mctoon.conv.utils.AppConstant;
import com.zhengtoon.mctoon.conv.utils.ToonCodeAppUtils;

import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 消息内容处理utils 144637
 */
public class MsgFormatUtils {


    /**
     * 处理随手拍过长消息    144637
     *
     * @param convContent
     * @return
     */
    public static String getConvContent(String convContent) {

        if (convContent.length() > AppConstant.CONV_CONTENT_LENGH_LIMIT) {
            convContent = convContent.substring(0, AppConstant.CONV_CONTENT_LENGH_LIMIT) + "...";
        }
        return convContent;
    }

    /**
     * 生成通知code     144637
     *
     * @param userId
     * @return
     */
    public static String getMsgCode(String userId) {
        ToonCodeInfo codeInfo = new ToonCodeInfo();
        codeInfo.setUserId(userId);
        codeInfo.setTimestamp(new Date().getTime());
        codeInfo.setToonType(AppConstant.TOON_CODE_TYPE_MSG);

        String code = ToonCodeAppUtils.encryptCode(codeInfo);
        code = URLEncoder.encode(code);
        return code;
    }

    /**
     * 获取发布时间  144637
     *
     * @param createTime
     * @return
     */
    public static String getConvPushTime(Long createTime) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return sdf.format(createTime);
    }


    /**
     * 获取积分项格式  144637
     *
     * @param scoreItem
     * @return
     */
    public static String getConvScoreItem(String scoreItem) {

        if (!scoreItem.contains("积分")) {
            scoreItem = scoreItem + "积分";
        }
        return scoreItem;
    }

    /**
     * 获取分值格式   144637
     *
     * @param score
     * @return
     */
    public static String getConvScore(String score) {
        if (!score.contains("分")) {
            score = score + "分";
        }
        return score;
    }

    /**
     * 获取栏目类型   144637
     *
     * @param typeCode
     * @return
     */
    public static String getConvType(Integer typeCode) {
        if (AppConstant.CONV_PRAISE_SOCIAL_WARN.equals(typeCode)) {
            return "社会警示";
        }

        if (AppConstant.CONV_PRAISE_BJ.equals(typeCode)) {
            return "最美门城";
        }

        if (AppConstant.CONV_REPORT.equals(typeCode)) {
            return "举报处理";
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(getConvPushTime(new Date().getTime()));
        System.out.println(getMsgCode("363463"));
    }


}
